syntax off "自动语法高亮
"winpos 5 5          " 设定窗口位置  
"set lines=40 columns=155    " 设定窗口大小  
"set nu              " 显示行号  
"set nu rnu "设置混合行号
"自动切换行号显示模式
set number
augroup numbertoggle
  autocmd!
  autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu   | endif
  autocmd BufLeave,FocusLost,InsertEnter,WinLeave   * if &nu                  | set nornu | endif
augroup END
set hidden
set cmdheight=2
set nobackup
set nowritebackup
set shortmess+=c
set guifont=Courier_New:h10:cANSI   " 设置字体  
set ruler           " 显示标尺  
set showcmd         " 输入的命令显示出来，看的清楚些  
set relativenumber  " 设置相对行号
"set whichwrap+=<,>,h,l   " 允许backspace和光标键跨越行边界(不建议)  
set foldenable      " 允许折叠  
set foldmethod=indent   " 缩进折叠  
"set background=dark "背景使用黑色 
set encoding=utf-8
set timeoutlen=300
set ttimeoutlen=50
" 设置配色方案
set termguicolors
if has('gui_running')
  set background=dark
  colorscheme default
else
  colorscheme PaperColor
endif
" 设置python的版本
set pyxversion=3
"-----
"浮动窗口 
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
"set fileencoding=utf-8"
set autowrite
set cursorline              " 突出显示当前行
set guioptions-=T           " 隐藏工具栏
set guioptions-=m           " 隐藏菜单栏
set foldcolumn=4
filetype plugin on 
" 去掉输入错误的提示声音
set noeb
" 在处理未保存或只读文件的时候，弹出确认
set confirm
" 自动缩进
set autoindent
set invhls
set cindent
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 在行和段开始处使用制表符
set smarttab 
" 历史记录数
set history=500
"用浅色高亮当前行"
autocmd InsertEnter * se nocul
autocmd InsertLeave * se cul
"搜索忽略大小写
set ignorecase
"搜索逐字符高亮
set hlsearch
"set incsearch
"行内替换
set gdefault
"编码设置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
"语言设置
set langmenu=zh_CN.UTF-8
set helplang=cn
"another config"
source ~/.vim/plug-config/hotkey.vim
source ~/.vim/plug-config/coc.vim
source ~/.vim/plug-config/patsnap.vim
source ~/.vim/plug-config/pluginlist.vim
source ~/.vim/plug-config/whichkey.vim
source ~/.vim/plug-config/function.vim
"config plugin 
set laststatus=2 
function! Buf_total_num()
    return len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
endfunction
function! File_size(f)
    let l:size = getfsize(expand(a:f))
    if l:size == 0 || l:size == -1 || l:size == -2
        return ''
    endif
    if l:size < 1024
        return l:size.' bytes'
    elseif l:size < 1024*1024
        return printf('%.1f', l:size/1024.0).'k'
    elseif l:size < 1024*1024*1024
        return printf('%.1f', l:size/1024.0/1024.0) . 'm'
    else
        return printf('%.1f', l:size/1024.0/1024.0/1024.0) . 'g'
    endif
endfunction

"airline set
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'default'
" path to the chrome or the command to open chrome(or other modern browsers)
let g:mkdp_path_to_chrome = "google-chrome-stable"
let g:python3_host_prog = '/usr/bin/python3'

" ===
" === vim-indent-guide
" ===
let g:indent_guides_guide_size = 1
let g:indent_guides_start_level = 2
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_color_change_percent = 1
silent! unmap <LEADER>ig
autocmd WinEnter * silent! unmap <LEADER>ig
"" fzf-preview config
"nnoremap <leader>f :FzfLua<CR>
"" markdown2ctags config
" Add support for markdown files in tagbar.
let g:tagbar_type_markdown = {
    \ 'ctagstype': 'markdown',
    \ 'ctagsbin' : 'markdown2ctags',
    \ 'ctagsargs' : '-f - --sort=yes --sro=»',
    \ 'kinds' : [
        \ 's:sections',
        \ 'i:images'
    \ ],
    \ 'sro' : '»',
    \ 'kind2scope' : {
        \ 's' : 'section',
    \ },
    \ 'sort': 0,
\ }
""设定文件类型
au BufRead,BufNewFile *.md set filetype=markdown
""默认回到上次编辑的地方
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
""markdown插件设置
let g:vim_markdown_folding_level = 5
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("nvim-0.5.0") || has("patch-8.1.1564")
  " Recently vim can merge signcolumn and number column into one
  set signcolumn=number
else
  set signcolumn=yes
endif

" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
if has('nvim')
  inoremap <silent><expr> <c-space> coc#refresh()
else
  inoremap <silent><expr> <c-@> coc#refresh()
endif

" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
""fzf config
" 输入上方，搜索列表在下方
"let $FZF_DEFAULT_OPTS = '--layout=reverse'
"let g:fzf_layout = {'down':'~40%'}
"浮动框显示
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
let g:indent_guides_guide_size            = 1  " 指定对齐线的尺寸
let g:indent_guides_start_level           = 2  " 从第二层开始可视化显示缩进
"glow setting
let g:glow_style = "~/mystyle.json"
"patsnap function setting 
let g:searchbrowser="microsoft-edge-stable"
"markdownpreview setting 
let g:mkdp_browser ='google-chrome-stable'
call which_key#register('<Space>', "g:which_key_map")
nnoremap <silent> <leader> :<c-u>WhichKey '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>WhichKeyVisual '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey  ','<CR>
"Auto pairs setting
lua require('nvim-autopairs').setup()
let g:niceblock_no_default_key_mappings = 0
autocmd FileType json syntax match Comment +\/\/.\+$+
lua require'colorizer'.setup()
